package cn.xspace.wnx.activity;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xspace.android.xafcommon.base.BaseActivity;
import com.xspace.android.xafcommon.been.BaseReturnBean;
import com.xspace.android.xafcommon.util.Constants;
import com.xspace.android.xafcommon.util.ErrorCode;
import com.xspace.android.xafcommon.util.EventBusConstant;
import com.xspace.android.xafcommon.util.LogUtil;
import com.xspace.android.xafcommon.util.LogUtils;
import com.xspace.android.xafcommon.util.T;
import com.xspace.android.xafcommon.view.dialog.ButtonClickListener;
import com.xspace.android.xafcommon.view.dialog.DialogHelp;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.xspace.app.view.TitleBar;
import cn.xspace.chatui.bean.MsgRecordEntity;
import cn.xspace.library.bean.Type;
import cn.xspace.library.util.BldNavigation;
import cn.xspace.library.util.MsgType;
import cn.xspace.library.util.MyInfoUtil;
import cn.xspace.library.util.OkHttpManager;
import cn.xspace.library.util.AuthorityController;
import cn.xspace.library.view.DividerLine;
import cn.xspace.library.view.FullyLinearLayoutManager;
import cn.xspace.wnx.R;
import cn.xspace.library.adapter.TreeRecycleViewAdapter;
import cn.xspace.wnx.entity.GroupEntity;
import cn.xspace.library.bean.OrgDeptUserBean;
import cn.xspace.wnx.util.ForwardHelper;
import cn.xspace.wnx.util.Navigator;
import cn.xspace.wnx.util.Notifier;
import cn.xspace.library.view.tree.bean.Node;
import de.greenrobot.event.EventBus;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * liuchen 创建于 2016/10/24.
 */
public class OrganizationActivityR extends BaseActivity implements TreeRecycleViewAdapter.IParentClickListener {

    private static final String TAG = OrganizationActivityR.class.getSimpleName();

    private TitleBar mTitle;
    //转发时用的数据
    private MsgRecordEntity recordEntity;
    /**
     * ==============本机构或者本部门==============
     **/
    // 组织机构的数据Adapter
    private TreeRecycleViewAdapter orgListAdapter;
    // 组织机构的数据
    private List<OrgDeptUserBean> orgList;
    // 组织机构的listView
    private RecyclerView orgListView;

    /**
     * ===============兼职机构=============
     */
    LinearLayout jobLinearLayout;
    // 兼职机构的数据Adapter
    private TreeRecycleViewAdapter jobListAdapter;
    // 兼职机构的数据
    private List<OrgDeptUserBean> jobList;
    // 兼职机构的listView
    private RecyclerView jobListView;
    // 兼职机构的标题
    private TextView jobTextview;

    /**
     * =============上级直属机构===============
     */
    LinearLayout zhishuUpLinearLayout;
    // 上级直属机构的数据Adapter
    private TreeRecycleViewAdapter zhishuUpListAdapter;
    // 上级直属机构的数据
    private List<OrgDeptUserBean> zhishuUpList;
    // 上级直属机构的listView
    private RecyclerView zhishuUpListView;
    // 上级直属机构的标题
    private TextView zhishuUpTextview;

    /**
     * ===============上级归口机构=============
     **/
    LinearLayout guikouUpLinearLayout;
    // 上级归口机构的数据Adapter
    private TreeRecycleViewAdapter guikouUpListAdapter;
    // 上级归口机构的数据
    private List<OrgDeptUserBean> guikouUpList;
    //上级归口机构的listView
    private RecyclerView guikouUpListView;
    //上级归口机构的标题
    private TextView guikouUpTextview;

    /**
     * =============下级直属机构===============
     */
    LinearLayout zhishuLinearLayout;
    // 下级直属机构的数据Adapter
    private TreeRecycleViewAdapter zhishuListAdapter;
    // 下级直属机构的数据
    private List<OrgDeptUserBean> zhishuList;
    // 下级直属机构的listView
    private RecyclerView zhishuListView;
    // 下级直属机构的标题
    private TextView zhishuTextview;

    /**
     * =============同级直属机构===============
     */
    LinearLayout zhishuEquLinearLayout;
    // 下级直属机构的数据Adapter
    private TreeRecycleViewAdapter zhishuEquListAdapter;
    // 下级直属机构的数据
    private List<OrgDeptUserBean> zhishuEquList;
    // 下级直属机构的listView
    private RecyclerView zhishuEquListView;
    // 下级直属机构的标题
    private TextView zhishuEquTextview;

    /**
     * ===============下级归口机构=============
     **/
    LinearLayout guikouLinearLayout;
    // 下级归口机构的数据Adapter
    private TreeRecycleViewAdapter guikouListAdapter;
    // 下级归口机构的数据
    private List<OrgDeptUserBean> guikouList;
    // 下级归口机构的lisView
    private RecyclerView guikouListView;
    // 下级归口机构的标题
    private TextView guikouTextview;

    // 本机构或者本部门聊天
    private boolean chat_with_selfdept = false;
    // 上级直属机构聊天
    private boolean chat_with_updirdept = false;
    // 上级归口机构聊天
    private boolean chat_with_upbelongdept = false;
    // 同级直属机构聊天
    private boolean chat_with_equivdirdept = false;
    // 下级直属机构聊天
    private boolean chat_with_dirdept = false;
    // 下级归口机构聊天
    private boolean chat_with_belongdept = false;

    private String user_id = "";
    private String dept_id = "";
    //用户真实所在的部门
    private String realDepId;
    private DividerLine dividerLine;

    /**
     * 存储加载过的机构的Id
     */
    private HashMap<String, List<OrgDeptUserBean>> orgLoadMap;
    /**
     * 存储加载过的兼职机构的Id
     */
    private HashMap<String, List<OrgDeptUserBean>> jobLoadMap;
    /**
     * 存储加载过的直属map
     */
    private HashMap<String, List<OrgDeptUserBean>> zhishuLoadMap;
    private HashMap<String, List<OrgDeptUserBean>> zhishuEquLoadMap;
    private HashMap<String, List<OrgDeptUserBean>> zhishuUpLoadMap;
    /**
     * 存储加载过的归口map
     */
    private HashMap<String, List<OrgDeptUserBean>> guikouLoadMap;
    private HashMap<String, List<OrgDeptUserBean>> guikouUpLoadMap;

    private List<String> lastNodeIdOrg = new ArrayList<>();

    int clickType = OrganizationType.ORGANIZATION;

    public interface OrganizationType {
        int ORGANIZATION = 1;
        int PART_TIME_JOB = 2;
        int ZHISHU_UP_ORG = 3;
        int ZHISHU_EQU_ORG = 4;
        int ZHISHU_ORG = 5;
        int GUIKOU_UP_ORG = 6;
        int GUIKOU_ORG = 7;
    }

    private PopupWindow popupWindow;
    private Animation ppshow;

    private OrgDeptUserBean lastDeptBean = null;
    Map<String, Object> orgMap;
    Map<String, Object> jobMap;
    Map<String, Object> zhishuUpMap;
    Map<String, Object> zhishuEquMap;
    Map<String, Object> zhishuMap;
    Map<String, Object> guikouUpMap;
    Map<String, Object> guikouMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(mContext);
    }

    @Override
    protected void getIntentData() {
        super.getIntentData();
        Bundle mBundle = getIntent().getBundleExtra(BldNavigation.KEY_BUNDLER);
        if (mBundle != null) {
            recordEntity = (MsgRecordEntity) mBundle.getSerializable(MsgForwardActivity.FORWARD_ENTITY);
        }
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_organization_r);
        ppshow = AnimationUtils.loadAnimation(this, R.anim.ppshow); //初始化popupWindow动画
    }

    @Override
    protected void initFindViewById() {
        super.initFindViewById();
        mTitle = (TitleBar) findViewById(R.id.title_bar);
        orgListView = (RecyclerView) findViewById(R.id.list_org);
        orgList = new ArrayList<>();

        //兼职
        jobLinearLayout = (LinearLayout) findViewById(R.id.linear_org_job);
        jobListView = (RecyclerView) findViewById(R.id.list_org_job);
        jobTextview = (TextView) findViewById(R.id.txt_job_title);
        jobList = new ArrayList<>();
        //上级直属
        zhishuUpLinearLayout = (LinearLayout) findViewById(R.id.linear_zhishu_up);
        zhishuUpListView = (RecyclerView) findViewById(R.id.list_zhishu_up);
        zhishuUpTextview = (TextView) findViewById(R.id.txt_zhishu_up_title);
        zhishuUpList = new ArrayList<>();
        //上级归口
        guikouUpLinearLayout = (LinearLayout) findViewById(R.id.linear_guikou_up);
        guikouUpListView = (RecyclerView) findViewById(R.id.list_guikou_up);
        guikouUpTextview = (TextView) findViewById(R.id.txt_guikou_up_title);
        guikouUpList = new ArrayList<>();
        //下级直属
        zhishuLinearLayout = (LinearLayout) findViewById(R.id.linear_org_zhishu);
        zhishuListView = (RecyclerView) findViewById(R.id.list_org_zhishu);
        zhishuTextview = (TextView) findViewById(R.id.txt_zhishu_title);
        zhishuList = new ArrayList<>();
        //同级直属
        zhishuEquLinearLayout = (LinearLayout) findViewById(R.id.linear_org_zhishu_equ);
        zhishuEquListView = (RecyclerView) findViewById(R.id.list_org_zhishu_equ);
        zhishuEquTextview = (TextView) findViewById(R.id.txt_zhishu_title_equ);
        zhishuEquList = new ArrayList<>();
        //下级归口
        guikouLinearLayout = (LinearLayout) findViewById(R.id.linear_org_guikou);
        guikouListView = (RecyclerView) findViewById(R.id.list_org_guikou);
        guikouTextview = (TextView) findViewById(R.id.txt_guikou_title);
        guikouList = new ArrayList<>();

    }

    private void commomDeal(RecyclerView mRecycleview, TreeRecycleViewAdapter mAdapter) {
        FullyLinearLayoutManager manager = new FullyLinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecycleview.setLayoutManager(manager);
        mRecycleview.addItemDecoration(dividerLine);
        mRecycleview.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        user_id = MyInfoUtil.getMyUserid(mContext);
        //用户所在机构的id而非登录登录的客户端的id
        dept_id = MyInfoUtil.getUserOrgId();
//        dept_id = MyInfoUtil.getUseOrgId(mContext);
        realDepId = MyInfoUtil.getUserDeptId();
        //用户所在机构name (机构为orgName)
        String dept_name = MyInfoUtil.getUserOrgName();

        initAuth();
        dividerLine = new DividerLine(DividerLine.VERTICAL);
        dividerLine.setSize(1);
        dividerLine.setColor(getResources().getColor(R.color.line));

        orgLoadMap = new HashMap<>();
        jobLoadMap = new HashMap<>();
        zhishuLoadMap = new HashMap<>();
        zhishuEquLoadMap = new HashMap<>();
        zhishuUpLoadMap = new HashMap<>();
        guikouLoadMap = new HashMap<>();
        guikouUpLoadMap = new HashMap<>();

        //用户所在机构或者部门
        if (chat_with_selfdept) {
            lastDeptBean = new OrgDeptUserBean();
            lastDeptBean.dept_id = dept_id;
            lastDeptBean.dept_name = dept_name;
            orgList.add(lastDeptBean);
            try {
                orgListAdapter = new TreeRecycleViewAdapter(mContext, orgList, 0, false, false, false);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

            orgMap = new HashMap<>();
            orgMap.put("user_id", user_id);
            orgMap.put("dept_id", dept_id);
            commomDeal(orgListView,orgListAdapter);
            requestNetWork(orgMap);
        }

        /**
         * 兼职机构
         */
        jobMap = new HashMap<>();
        jobMap.put("user_id", user_id);
        jobLoadMap = new HashMap<>();
        jobList = new ArrayList<>();
        try {
            jobListAdapter = new TreeRecycleViewAdapter(mContext, jobList, 0, false, false, false);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


        requestNetWorkJob();
        commomDeal(jobListView,jobListAdapter);

        /**
         * 归口机构
         */
        // 上级归口机构
        if (chat_with_upbelongdept) {
            guikouUpMap = new HashMap<>();
            guikouUpMap.put("user_id", user_id);
            guikouUpMap.put("dept_id", dept_id);
            guikouUpMap.put("query_type", "up");
            try {
                guikouUpListAdapter = new TreeRecycleViewAdapter(mContext, guikouUpList, 0, false,
                        false, false);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            commomDeal(guikouUpListView,guikouUpListAdapter);
            requestGuikou(OrganizationType.GUIKOU_UP_ORG);
        } else {
            guikouUpLinearLayout.setVisibility(View.GONE);
        }
        // 下级归口机构
        if (chat_with_belongdept) {
            guikouMap = new HashMap<>();
            guikouMap.put("user_id", user_id);
            guikouMap.put("dept_id", dept_id);
            guikouMap.put("query_type", "down");
            try {
                guikouListAdapter = new TreeRecycleViewAdapter(mContext, guikouList, 0, false, false,
                        false);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            commomDeal(guikouListView,guikouListAdapter);
            requestGuikou(OrganizationType.GUIKOU_ORG);
        } else {
            guikouLinearLayout.setVisibility(View.GONE);
        }

        /**
         * 直属机构
         */
        //上级直属机构
        if (chat_with_updirdept) {
            zhishuUpMap = new HashMap<>();
            zhishuUpMap.put("user_id", user_id);
            zhishuUpMap.put("dept_id", dept_id);
            zhishuUpMap.put("query_type", "up");
            try {
                zhishuUpListAdapter = new TreeRecycleViewAdapter(mContext, zhishuUpList, 0, false,
                        false, false);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            commomDeal(zhishuUpListView,zhishuUpListAdapter);
            requestZhishu(OrganizationType.ZHISHU_UP_ORG);
        } else {
            zhishuUpLinearLayout.setVisibility(View.GONE);
        }
        //同级直属机构
        if (chat_with_equivdirdept) {
            zhishuEquMap = new HashMap<>();
            zhishuEquMap.put("user_id", user_id);
            zhishuEquMap.put("dept_id", dept_id);
            zhishuEquMap.put("query_type", "equ");
            try {
                zhishuEquListAdapter = new TreeRecycleViewAdapter(mContext, zhishuEquList, 0, false,
                        false, false);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            commomDeal(zhishuEquListView,zhishuEquListAdapter);
            requestZhishu(OrganizationType.ZHISHU_EQU_ORG);
        } else {
            zhishuEquLinearLayout.setVisibility(View.GONE);
        }
        //下级直属
        if (chat_with_dirdept) {
            zhishuMap = new HashMap<>();
            zhishuMap.put("user_id", user_id);
            zhishuMap.put("dept_id", dept_id);
            zhishuMap.put("query_type", "down");
            try {
                zhishuListAdapter = new TreeRecycleViewAdapter(mContext, zhishuList, 0, false,
                        false, false);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            commomDeal(zhishuListView,zhishuListAdapter);
            requestZhishu(OrganizationType.ZHISHU_ORG);
        } else {
            zhishuLinearLayout.setVisibility(View.GONE);
        }
    }

    /**
     * 判断权限,用于显示
     */
    private void initAuth() {
        // 本机构或者本部门聊天
        if (AuthorityController.getInstance().isCanViewAddressbookMyOrg()) chat_with_selfdept = true;
        // 上级直属机构聊天
        if (AuthorityController.getInstance().isUpDirDept()) chat_with_updirdept = true;
        // 上级归口机构聊天
        if (AuthorityController.getInstance().isUpBelong()) chat_with_upbelongdept = true;
        // 同级直属机构聊天
        if (AuthorityController.getInstance().isEquivDirDept()) chat_with_equivdirdept = true;
        // 下级直属机构聊天
        if (AuthorityController.getInstance().isDirDept()) chat_with_dirdept = true;
        // 下级归口机构聊天
        if (AuthorityController.getInstance().isBelong()) chat_with_belongdept = true;
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        mTitle.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTitle.setTitle(getString(R.string.organization));
        mTitle.setRightLayoutVisibility(View.GONE);

        if (orgListAdapter != null) {
            orgListAdapter.setOnTreeNodeClickListener(new TreeRecycleViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position, boolean isImg) {
                    clickType = OrganizationType.ORGANIZATION;
                    commonClickEvent(node, position, isImg);
                }
            });
            orgListAdapter.setiParentClickListener(this);
        }
        //监听兼职部门点击
        if (jobListAdapter != null) {
            jobListAdapter.setOnTreeNodeClickListener(new TreeRecycleViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position, boolean isImg) {
                    clickType = OrganizationType.PART_TIME_JOB;
                    commonClickEvent(node, position, isImg);
                }
            });
            jobListAdapter.setiParentClickListener(this);
        }
        //监听上级直属部门点击
        if (zhishuUpListAdapter != null) {
            zhishuUpListAdapter.setOnTreeNodeClickListener(new TreeRecycleViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position, boolean isImg) {
                    clickType = OrganizationType.ZHISHU_UP_ORG;
                    commonClickEvent(node, position, isImg);
                }
            });
            zhishuUpListAdapter.setiParentClickListener(this);
        }
        //监听上级归口部门点击
        if (guikouUpListAdapter != null) {
            guikouUpListAdapter.setOnTreeNodeClickListener(new TreeRecycleViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position, boolean isImg) {
                    clickType = OrganizationType.GUIKOU_UP_ORG;
                    commonClickEvent(node, position, isImg);
                }
            });
            guikouUpListAdapter.setiParentClickListener(this);
        }

        //监听下级或者部门点击
        if (zhishuListAdapter != null) {
            zhishuListAdapter.setOnTreeNodeClickListener(new TreeRecycleViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position, boolean isImg) {
                    clickType = OrganizationType.ZHISHU_ORG;
                    commonClickEvent(node, position, isImg);
                }
            });
            zhishuListAdapter.setiParentClickListener(this);
        }
        //监听同级直属部门点击
        if (zhishuEquListAdapter != null) {
            zhishuEquListAdapter.setOnTreeNodeClickListener(new TreeRecycleViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position, boolean isImg) {
                    clickType = OrganizationType.ZHISHU_EQU_ORG;
                    commonClickEvent(node, position, isImg);
                }
            });
            zhishuEquListAdapter.setiParentClickListener(this);
        }

        //监听下级归口部门点击
        if (guikouListAdapter != null) {
            guikouListAdapter.setOnTreeNodeClickListener(new TreeRecycleViewAdapter.OnTreeNodeClickListener() {
                @Override
                public void onClick(Node node, int position, boolean isImg) {
                    clickType = OrganizationType.GUIKOU_ORG;
                    commonClickEvent(node, position, isImg);
                }
            });
            guikouListAdapter.setiParentClickListener(this);
        }
    }

    @Override
    public void onRightClick(final OrgDeptUserBean orgBean, final Node node, int position, RelativeLayout iconRight) {
        popDismiss();
        View contentView = View.inflate(mContext, R.layout.pop_org_item, null);
        TextView inGroupChat = (TextView) contentView.findViewById(R.id.tv_pp_in_group_chat);
        TextView createTemp = (TextView) contentView.findViewById(R.id.tv_pop_create_temp);
        LogUtil.d(TAG, "clickbean的部门ID>>" + orgBean.dept_id + "用户的部门ID:" + realDepId + " 用户的机构的ID:" + dept_id);
        LogUtil.d(TAG, "clickbean>> hx Id" + orgBean.hx_groupid);
        LogUtil.d(TAG, "clickbean:" + orgBean.toString() + "\nnode:" + node.toString());

        if (recordEntity != null) { //转发情况
            LogUtil.d(TAG, "wubaojie>>>onRightClick: 转发模式");
            if (TextUtils.isEmpty(node.getpId())) {
                inGroupChat.setText(R.string.forward_to_org);
            } else {
                inGroupChat.setText(R.string.forward_to_dep);
            }
            inGroupChat.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    popDismiss();
                    if (TextUtils.isEmpty(node.getpId())) { //是机构节点
                        if (TextUtils.equals(dept_id, orgBean.dept_id)) { //且是本机构节点
                            forwardTo(orgBean);
                        } else {
                            DialogHelp.getDialog(mContext).setMessage(R.string.no_permission_forward_to_org)
                                    .setPositiveButton(R.string.button_ok, null)
                                    .show();
                        }
                    } else { //是部门节点
                        if (TextUtils.equals(realDepId, orgBean.dept_id)) { //是自己部门的节点
                            forwardTo(orgBean);
                        } else {
                            DialogHelp.getDialog(mContext).setMessage(R.string.no_permission_forward_to_dep)
                                    .setPositiveButton(R.string.button_ok, null)
                                    .show();
                        }
                    }

                }
            });
        } else { //正常情况
            LogUtil.d(TAG, "wubaojie>>>onRightClick: 正常模式");
            inGroupChat.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    popDismiss();
                    if (TextUtils.isEmpty(node.getpId())) { //是机构节点
                        if (TextUtils.equals(dept_id, orgBean.dept_id)) { //且是本机构节点
                            LogUtil.d(TAG, "wubaojie>>>onClick: 本机构的群聊,直接进群组:" + orgBean.dept_name);
                            inGroupChat(orgBean);
                        } else { //非本机构节点
                            LogUtil.d(TAG, "wubaojie>>>onClick: 非本机构的部门,没有权限发起会话:" + orgBean.dept_name);
                            DialogHelp.getDialog(mContext).setMessage(R.string.no_permission_create_org)
                                    .setPositiveButton(R.string.button_ok, null)
                                    .show();
                        }
                    } else { //是部门节点
                        if (TextUtils.equals(realDepId, orgBean.dept_id)) { //是自己部门的节点
                            LogUtil.d(TAG, "wubaojie>>>onClick: 自己部门的群聊,直接进群组:" + orgBean.dept_name);
                            inGroupChat(orgBean);
                        } else {
                            if (TextUtils.equals(dept_id, orgBean.dept_pid)) { //是自己机构下的部门
                                LogUtil.d(TAG, "wubaojie>>>onClick: 本机构的非自己部门的群聊,发起会话:" + orgBean.dept_name);
                                createTempChat(orgBean); //发起群聊
                            } else { //非自己机构下的部门不能发起群聊
                                LogUtil.d(TAG, "wubaojie>>>onClick: 非本机构的部门,没有权限发起会话:" + orgBean.dept_name);
                                DialogHelp.getDialog(mContext).setMessage(R.string.no_permission_create_dep)
                                        .setPositiveButton(R.string.button_ok, null)
                                        .show();
                            }
                        }
                    }
                }
            });
        }
        popupWindow = new PopupWindow(contentView, -2, -2, true);
        // 必须设置背景颜色,动画效果才会生效
        popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        // popupWindow.showAsDropDown(view, 60, -view.getHeight());
        int[] location = new int[2];
        iconRight.getLocationInWindow(location);
        LogUtil.d(TAG, "wubaojie>>>onRightClick: iconHight:" + iconRight.getMeasuredHeight());
        LogUtil.d(TAG, "wubaojie>>>onRightClick: iconRight:" + iconRight.getMeasuredWidth() / 2);
        popupWindow.showAtLocation(iconRight, Gravity.RIGHT + Gravity.TOP, iconRight.getMeasuredWidth() / 2,
                location[1] + iconRight.getMeasuredHeight());
        // 可以添加任意的动画资源
        contentView.startAnimation(ppshow);
    }

    private void inGroupChat(OrgDeptUserBean orgBean) {
        //跳转到群聊界面
        Bundle dataBundle = new Bundle();
        dataBundle.putString(BldNavigation.SENDER_ID, orgBean.dept_id);
        dataBundle.putInt(BldNavigation.CHAT_TYPE, MsgType.CHAT_CROUP.toNumber());
        dataBundle.putString(BldNavigation.CHAT_NAME, orgBean.dept_name);
        dataBundle.putInt(BldNavigation.GROUP_TYPE, Type.GroupType.ORGANIZATION);
        dataBundle.putString(BldNavigation.CHAT_SENDER_LOGO, "");
        Navigator.startChatActivity(mContext, dataBundle);
    }

    private void forwardTo(final OrgDeptUserBean orgBean) {
        ForwardHelper.getInstance().confirmBeforeForward(mContext, new ButtonClickListener() {
            @Override
            public void buttonClick(View view) {
                LogUtil.d("确认");
                GroupEntity groupEntity = new GroupEntity();
                groupEntity.group_id = orgBean.dept_id;
                groupEntity.group_name = orgBean.dept_name;
                groupEntity.group_logo = orgBean.logo;
                groupEntity.group_type = Type.GroupType.ORGANIZATION;
                ForwardHelper.getInstance().sendMessageGroup(mContext, recordEntity, groupEntity);
            }
        }, recordEntity, orgBean.dept_name);
    }

    /**
     * 对所选部门发起临时会话
     *
     * @param orgBean
     */
    private void createTempChat(OrgDeptUserBean orgBean) {
        showWaitDialog();
        Map<String, Object> groupMap = new HashMap<>();
        groupMap.put("user_id", user_id);
        groupMap.put("group_orgid", dept_id);
        groupMap.put("dept_id", orgBean.dept_id);
        OkHttpManager.getInstance().commonRequest(Constants.CREATE_USER_GROUP, groupMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseReturnBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        hideWaitDialog();
                        T.showShort(mContext, e.getMessage());
                    }


                    @Override
                    public void onNext(BaseReturnBean baseReturnBean) {
                        hideWaitDialog();
                        if (ErrorCode.SUCCESS_CODE_WNX.equals(baseReturnBean.code)) {
                            Bundle dataBundle = new Bundle();
                            T.showShort(mContext, R.string.group_create_success);
                            Notifier.getInstance().isNeedNotice = false;
                            try {
                                JSONObject dataJson = new JSONObject(baseReturnBean.data);
                                String groupId = dataJson.optString("group_id");
                                String group_logo = dataJson.optString("group_logo");
                                LogUtil.d("创建成功" + groupId + ">>>" + group_logo);
                                dataBundle.putString(BldNavigation.SENDER_ID, groupId);
                                dataBundle.putInt(BldNavigation.CHAT_TYPE, MsgType.CHAT_CROUP.toNumber());
                                dataBundle.putString(BldNavigation.CHAT_NAME, "");
                                dataBundle.putString(BldNavigation.CHAT_SENDER_LOGO, "");
                                dataBundle.putInt(BldNavigation.GROUP_TYPE, Type.GroupType.TEMP_GROUP); //刚创建的为临时会话
                                Navigator.startChatActivity(mContext, dataBundle);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
                            T.showShort(mContext, baseReturnBean.desc);
                        }
                    }
                });
    }

    /**
     * 组织机构访问网络
     */
    private void requestNetWork(Map<String, Object> map) {
        showWaitDialog();
        registerSubscription(OkHttpManager.getInstance().commonRequest(Constants.QUERY_ORG, map)
                .subscribeOn(Schedulers.io())
                .map(new Func1<BaseReturnBean, List<OrgDeptUserBean>>() {
                    @Override
                    public List<OrgDeptUserBean> call(BaseReturnBean baseReturnBean) {
                        LogUtil.d(TAG, "wubaojie>>>call: baseReturnBean:" + baseReturnBean.data);
                        List<OrgDeptUserBean> dataList = new ArrayList<>();
                        JSONObject topJson;
                        JSONArray deptArray;
                        JSONArray userArray;
                        try {
                            topJson = new JSONObject(baseReturnBean.data);

                            //每个机构下面添加群聊的入口，isChatGroup 为true标识群聊。存放上一个部门的环信环信Id
//                            if (!TextUtils.isEmpty(lastDeptBean.dept_id)) {
//                                OrgDeptUserBean userBean = new OrgDeptUserBean();
////                                userBean.hx_groupid = lastDeptBean.hx_groupid;
//                                userBean.dept_name = lastDeptBean.dept_name + "群组";
//                                userBean.isGroupChat = true;
//                                userBean.isLeaf = true;
//                                userBean.dept_pid = lastDeptBean.dept_id;
//                                userBean.dept_id = lastDeptBean.dept_id + "群组";
//                                dataList.add(userBean);
//                            }
                            deptArray = topJson.getJSONArray("deptList"); //部门列表
                            for (int i = 0; i < deptArray.length(); i++) {
                                JSONObject deptJson = deptArray.getJSONObject(i);
                                OrgDeptUserBean deptBean = new OrgDeptUserBean();
                                deptBean.dept_id = deptJson.optString("dept_id");
                                deptBean.dept_name = deptJson.optString("dept_name");
                                deptBean.dept_code = deptJson.optString("dept_code");
                                deptBean.dept_pid = deptJson.optString("dept_pid");
                                deptBean.dept_members = deptJson.optString("dept_members");
                                deptBean.hx_groupid = deptJson.optString("hx_groupid");
                                deptBean.isLeaf = false;
                                dataList.add(deptBean);
                            }
                            userArray = topJson.getJSONArray("userList");
                            for (int i = 0; i < userArray.length(); i++) {
                                OrgDeptUserBean userBean = new OrgDeptUserBean();
                                JSONObject userJson = userArray.getJSONObject(i);
                                userBean.dept_pid = lastDeptBean.dept_id;
                                userBean.dept_id = userJson.optString("user_id");
                                userBean.user_id = userJson.optString("user_id");
                                userBean.dept_name = userJson.optString("user_name");
                                userBean.user_sex = userJson.optString("user_sex");
                                userBean.user_name = userJson.optString("user_name");
                                userBean.user_logo = userJson.optString("user_logo");
                                userBean.isMainDept = userJson.optString("user_ismain_job");
                                userBean.isLeaf = true;
                                dataList.add(userBean);
                            }
                            LogUtil.d(TAG, "dataList size " + dataList.size());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        return dataList;
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<OrgDeptUserBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        hideWaitDialog();
                        e.printStackTrace();
                        T.showShort(mContext, e.getMessage());
                    }

                    @Override
                    public void onNext(List<OrgDeptUserBean> orgDeptUserBeen) {
                        hideWaitDialog();
                        LogUtil.d(TAG, "dataList onNext " + orgDeptUserBeen.size());
                        if (clickType == OrganizationType.ORGANIZATION) {
                            orgLoadMap.put(lastDeptBean.dept_id, orgDeptUserBeen);
                            orgList.addAll(orgDeptUserBeen);
                            lastNodeIdOrg = orgListAdapter.getLastNodeId();
                            orgListAdapter.setDataSaveState(orgList, 1);
                            LogUtil.d(TAG, "lastNodeIdOrg size " + lastNodeIdOrg.size() + "  lastNodeIdOrg " +
                                    lastNodeIdOrg.toString());
//                            lastNodeIdOrg.add(lastDeptBean.dept_id);
//                            orgListAdapter.collapseNodeIdList(lastNodeIdOrg);
                            orgListAdapter.notifyDataSetChanged();
                        } else if (clickType == OrganizationType.PART_TIME_JOB) {
                            jobLoadMap.put(lastDeptBean.dept_id, orgDeptUserBeen);
                            jobList.addAll(orgDeptUserBeen);
                            lastNodeIdOrg = jobListAdapter.getLastNodeId();
                            jobListAdapter.setDataSaveState(jobList, 1);
                            LogUtil.d(TAG, "lastNodeIdOrg size " + lastNodeIdOrg.size() + "  lastNodeIdOrg " +
                                    lastNodeIdOrg.toString());
                            lastNodeIdOrg.add(lastDeptBean.dept_id);
                            jobListAdapter.collapseNodeIdList(lastNodeIdOrg);
                        } else if (clickType == OrganizationType.ZHISHU_ORG) { //下级直属
                            zhishuLoadMap.put(lastDeptBean.dept_id, orgDeptUserBeen);
                            zhishuList.addAll(orgDeptUserBeen);
                            lastNodeIdOrg = zhishuListAdapter.getLastNodeId();
                            zhishuListAdapter.setDataSaveState(zhishuList, 1);
                            LogUtil.d(TAG, "lastNodeIdOrg size " + lastNodeIdOrg.size() + "  lastNodeIdOrg " +
                                    lastNodeIdOrg.toString());
                            lastNodeIdOrg.add(lastDeptBean.dept_id);
                            zhishuListAdapter.collapseNodeIdList(lastNodeIdOrg);
                        } else if (clickType == OrganizationType.ZHISHU_EQU_ORG) { //同级直属
                            zhishuEquLoadMap.put(lastDeptBean.dept_id, orgDeptUserBeen);
                            zhishuEquList.addAll(orgDeptUserBeen);
                            lastNodeIdOrg = zhishuEquListAdapter.getLastNodeId();
                            zhishuEquListAdapter.setDataSaveState(zhishuEquList, 1);
                            LogUtil.d(TAG, "lastNodeIdOrg size " + lastNodeIdOrg.size() + "  lastNodeIdOrg " +
                                    lastNodeIdOrg.toString());
                            lastNodeIdOrg.add(lastDeptBean.dept_id);
                            zhishuEquListAdapter.collapseNodeIdList(lastNodeIdOrg);
                        } else if (clickType == OrganizationType.ZHISHU_UP_ORG) { //上级直属
                            zhishuUpLoadMap.put(lastDeptBean.dept_id, orgDeptUserBeen);
                            zhishuUpList.addAll(orgDeptUserBeen);
                            lastNodeIdOrg = zhishuUpListAdapter.getLastNodeId();
                            zhishuUpListAdapter.setDataSaveState(zhishuUpList, 1);
                            LogUtil.d(TAG, "lastNodeIdOrg size " + lastNodeIdOrg.size() + "  lastNodeIdOrg " +
                                    lastNodeIdOrg.toString());
                            lastNodeIdOrg.add(lastDeptBean.dept_id);
                            zhishuUpListAdapter.collapseNodeIdList(lastNodeIdOrg);
                        } else if (clickType == OrganizationType.GUIKOU_ORG) { //下级归口
                            guikouLoadMap.put(lastDeptBean.dept_id, orgDeptUserBeen);
                            guikouList.addAll(orgDeptUserBeen);
                            lastNodeIdOrg = guikouListAdapter.getLastNodeId();
                            guikouListAdapter.setDataSaveState(guikouList, 1);
                            LogUtil.d(TAG, "lastNodeIdOrg size " + lastNodeIdOrg.size() + "  lastNodeIdOrg " +
                                    lastNodeIdOrg.toString());
                            lastNodeIdOrg.add(lastDeptBean.dept_id);
                            guikouListAdapter.collapseNodeIdList(lastNodeIdOrg);
                        } else if (clickType == OrganizationType.GUIKOU_UP_ORG) { //上级归口
                            guikouUpLoadMap.put(lastDeptBean.dept_id, orgDeptUserBeen);
                            guikouUpList.addAll(orgDeptUserBeen);
                            lastNodeIdOrg = guikouUpListAdapter.getLastNodeId();
                            guikouUpListAdapter.setDataSaveState(guikouUpList, 1);
                            LogUtil.d(TAG, "lastNodeIdOrg size " + lastNodeIdOrg.size() + "  lastNodeIdOrg " +
                                    lastNodeIdOrg.toString());
                            lastNodeIdOrg.add(lastDeptBean.dept_id);
                            guikouUpListAdapter.collapseNodeIdList(lastNodeIdOrg);
                        }
                    }
                }));

    }

    /**
     * 查询兼职
     */
    private void requestNetWorkJob() {
        showWaitDialog();
        registerSubscription(OkHttpManager.getInstance().commonRequest(Constants.QUERY_PART_TIMEDEPT, jobMap)
                .subscribeOn(Schedulers.io())
                .map(new Func1<BaseReturnBean, List<OrgDeptUserBean>>() {

                    @Override
                    public List<OrgDeptUserBean> call(BaseReturnBean baseReturnBean) {
                        LogUtils.d("map");
                        List<OrgDeptUserBean> dataList = new Gson().fromJson(baseReturnBean.data,
                                new TypeToken<ArrayList<OrgDeptUserBean>>() {
                                }.getType());
                        if (dataList != null) {
                            LogUtils.d(dataList.toString());
                        } else {
                            LogUtils.d(" dataList is null");
                        }
                        return dataList;
                    }
                }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<OrgDeptUserBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        hideWaitDialog();
                        T.showShort(mContext, e.getMessage());
                    }

                    @Override
                    public void onNext(List<OrgDeptUserBean> orgDeptUserBeen) {
                        hideWaitDialog();
                        if (orgDeptUserBeen.size() == 0) {
                            jobLinearLayout.setVisibility(View.GONE);
                            return;
                        }
                        LogUtils.d(" dataList " + orgDeptUserBeen.size());
                        jobList.addAll(orgDeptUserBeen);
                        jobListAdapter.setData(jobList, 0);
                        jobListAdapter.notifyDataSetChanged();
                    }
                }));
    }

    /**
     * 查询直属
     */
    private void requestZhishu(final int zhishuType) {
        showWaitDialog();
        String url = Constants.QUERY_DIRECT_UNIT;
        Map<String, Object> map;
        if (zhishuType == OrganizationType.ZHISHU_UP_ORG) { //上级直属
            map = zhishuUpMap;
        } else if (zhishuType == OrganizationType.ZHISHU_EQU_ORG) { //同级级直属
            map = zhishuEquMap;
        } else { //下级直属
            map = zhishuMap;
        }
        registerSubscription(OkHttpManager.getInstance().commonRequest(url, map)
                .subscribeOn(Schedulers.io())
                .map(new Func1<BaseReturnBean, List<OrgDeptUserBean>>() {

                    @Override
                    public List<OrgDeptUserBean> call(BaseReturnBean baseReturnBean) {
                        LogUtil.d(TAG, "wubaojie>>>call: " + baseReturnBean.data);
                        List<OrgDeptUserBean> dataList = new Gson().fromJson(baseReturnBean.data,
                                new TypeToken<ArrayList<OrgDeptUserBean>>() {
                                }.getType());
                        if (dataList != null) {
                            LogUtils.d(dataList.toString());
                        } else {
                            LogUtils.d(" dataList is null");
                        }
                        return dataList;
                    }
                }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<OrgDeptUserBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        hideWaitDialog();
                        T.showShort(mContext, e.getMessage());
                    }

                    @Override
                    public void onNext(List<OrgDeptUserBean> orgDeptUserBeen) {
                        hideWaitDialog();
                        if (orgDeptUserBeen.size() == 0) {
                            if (zhishuType == OrganizationType.ZHISHU_UP_ORG) { //上级直属
                                zhishuUpLinearLayout.setVisibility(View.GONE);
                            } else if (zhishuType == OrganizationType.ZHISHU_EQU_ORG) { //同级直属
                                zhishuEquLinearLayout.setVisibility(View.GONE);
                            } else { //下级直属
                                zhishuLinearLayout.setVisibility(View.GONE);
                            }
                            return;
                        }
                        LogUtil.d(TAG, "wubaojie>>>onNext: dataList:" + orgDeptUserBeen.size());
                        if (zhishuType == OrganizationType.ZHISHU_UP_ORG) { //上级直属
                            zhishuUpList.addAll(orgDeptUserBeen);
                            zhishuUpListAdapter.setData(zhishuUpList, 0);
                            zhishuUpListAdapter.notifyDataSetChanged();
                        } else if (zhishuType == OrganizationType.ZHISHU_EQU_ORG) { //同级直属
                            zhishuEquList.addAll(orgDeptUserBeen);
                            zhishuEquListAdapter.setData(zhishuEquList, 0);
                            zhishuEquListAdapter.notifyDataSetChanged();
                        } else { //下级直属
                            zhishuList.addAll(orgDeptUserBeen);
                            zhishuListAdapter.setData(zhishuList, 0);
                            zhishuListAdapter.notifyDataSetChanged();
                        }
                    }
                }));

    }

    /**
     * 查询归口
     *
     * @param guiKouType
     */
    private void requestGuikou(final int guiKouType) {
        showWaitDialog();
        String url = Constants.QUERY_BELONG_DEPT;
        Map<String, Object> map;
        if (guiKouType == OrganizationType.GUIKOU_UP_ORG) { //上级归口
            map = guikouUpMap;
        } else { //下级归口
            map = guikouMap;
        }
        registerSubscription(OkHttpManager.getInstance().commonRequest(url, map)
                .subscribeOn(Schedulers.io())
                .map(new Func1<BaseReturnBean, List<OrgDeptUserBean>>() {

                    @Override
                    public List<OrgDeptUserBean> call(BaseReturnBean baseReturnBean) {

                        return new Gson().fromJson(baseReturnBean.data,
                                new TypeToken<ArrayList<OrgDeptUserBean>>() {
                                }.getType());
                    }
                }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<OrgDeptUserBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        hideWaitDialog();
                        T.showShort(mContext, e.getMessage());
                    }

                    @Override
                    public void onNext(List<OrgDeptUserBean> orgDeptUserBeen) {
                        hideWaitDialog();
                        if (orgDeptUserBeen.size() == 0) {
                            if (guiKouType == OrganizationType.GUIKOU_UP_ORG) {
                                guikouUpLinearLayout.setVisibility(View.GONE);
                            } else {
                                guikouLinearLayout.setVisibility(View.GONE);
                            }
                            return;
                        }
                        LogUtil.d(TAG, "wubaojie>>>onNext: dataList:" + orgDeptUserBeen.size());
                        if (guiKouType == OrganizationType.GUIKOU_UP_ORG) { //上级归口
                            guikouUpList.addAll(orgDeptUserBeen);
                            guikouUpListAdapter.setData(guikouUpList, 0);
                            guikouUpListAdapter.notifyDataSetChanged();
                        } else { //下级归口
                            guikouList.addAll(orgDeptUserBeen);
                            guikouListAdapter.setData(guikouList, 0);
                            guikouListAdapter.notifyDataSetChanged();
                        }
                    }
                }));

    }

//    Subscriber<List<OrgDeptUserBean>> orgSubscriber =;

    /**
     * 点击事件共同处理
     *
     * @param node
     * @param position
     * @param isImg
     */
    private void commonClickEvent(Node node, int position, boolean isImg) {
        LogUtil.d(TAG, "setOnTreeNodeClickListener");
        final OrgDeptUserBean orgBean = (OrgDeptUserBean) node.getObject();
        if (orgBean == null) {
            return;
        }
        if (orgBean.isLeaf) { //叶子节点，跳转到个人名片
            LogUtil.d(TAG, "orgBean.isLeaf");
            if (recordEntity != null) { //recordEntity为转发传递的数据,跳转转发页面
                ForwardHelper.getInstance().confirmBeforeForward(mContext, new ButtonClickListener() {
                            @Override
                            public void buttonClick(View view) {
                                LogUtil.d(TAG, "wubaojie>>>buttonClick: 确认转发");
                                ForwardHelper.getInstance().sendMessageRecordSingleChat(mContext, recordEntity,
                                        orgBean);
                            }
                        },
                        recordEntity,
                        orgBean.user_name);
                //转发
                return;
            }
            //不是转发,就打开个人信息页面
            Navigator.startPersonCardActivity(mContext, orgBean.dept_id);
        } else { //枝节点
            LogUtil.d(TAG, "wubaojie>>>commonClickEvent: clickEventType:" + clickType);
//            if (node.isExpand()) {
//                LogUtil.d(TAG, "orgBean.isExpand()");
//                if (clickType == OrganizationType.ORGANIZATION) {
//                    orgListAdapter.expandOrCollapse(position);
//                } else if (clickType == OrganizationType.PART_TIME_JOB) {
//                    jobListAdapter.expandOrCollapse(position);
//                } else if (clickType == OrganizationType.ORGANIZATION.ZHISHU_ORG) {
//                    zhishuListAdapter.expandOrCollapse(position);
//                } else if (clickType == OrganizationType.GUIKOU_ORG) {
//                    guikouListAdapter.expandOrCollapse(position);
//                }
//            } else {
            LogUtil.d(TAG, "orgBean.isExpand NOT ()");
            if (!checkOrgLoad(orgBean)) { //没有获取过数据,访问网路获取
                node.setExpand(!node.isExpand());
                lastDeptBean = orgBean;

                if (clickType == OrganizationType.ORGANIZATION) { //本机构或者本部门
                    orgMap.put("dept_id", lastDeptBean.dept_id);
                    //机构打开机构节点
                    requestNetWork(orgMap);
                } else if (clickType == OrganizationType.PART_TIME_JOB) { //兼职机构
                    jobMap.put("dept_id", lastDeptBean.dept_id);
                    //机构打开机构节点
                    requestNetWork(jobMap);
                } else if (clickType == OrganizationType.ZHISHU_ORG) { // 下级直属机构
                    zhishuMap.put("dept_id", lastDeptBean.dept_id);
                    //机构打开机构节点
                    requestNetWork(zhishuMap);
                } else if (clickType == OrganizationType.ZHISHU_UP_ORG) { //上级直属机构
                    zhishuUpMap.put("dept_id", lastDeptBean.dept_id);
                    //机构打开机构节点
                    requestNetWork(zhishuUpMap);
                } else if (clickType == OrganizationType.ZHISHU_EQU_ORG) { //下级直属机构
                    zhishuEquMap.put("dept_id", lastDeptBean.dept_id);
                    //机构打开机构节点
                    requestNetWork(zhishuEquMap);
                } else if (clickType == OrganizationType.GUIKOU_ORG) { //下级归口机构
                    guikouMap.put("dept_id", lastDeptBean.dept_id);
                    //机构打开机构节点
                    requestNetWork(guikouMap);
                } else if (clickType == OrganizationType.GUIKOU_UP_ORG) { //上级归口机构
                    guikouUpMap.put("dept_id", lastDeptBean.dept_id);
                    //机构打开机构节点
                    requestNetWork(guikouUpMap);
                }
            } else { //展开或者关闭界面
                if (clickType == OrganizationType.ORGANIZATION) {
                    orgListAdapter.expandOrCollapse(position);
                } else if (clickType == OrganizationType.PART_TIME_JOB) {
                    jobListAdapter.expandOrCollapse(position);
                } else if (clickType == OrganizationType.ZHISHU_ORG) {
                    zhishuListAdapter.expandOrCollapse(position);
                } else if (clickType == OrganizationType.ZHISHU_UP_ORG) {
                    zhishuUpListAdapter.expandOrCollapse(position);
                } else if (clickType == OrganizationType.ZHISHU_EQU_ORG) {
                    zhishuEquListAdapter.expandOrCollapse(position);
                } else if (clickType == OrganizationType.GUIKOU_ORG) {
                    guikouListAdapter.expandOrCollapse(position);
                } else if (clickType == OrganizationType.GUIKOU_UP_ORG) {
                    guikouUpListAdapter.expandOrCollapse(position);
                }
            }
//            }
        }
    }

    /**
     * 检查是否已经获取过数据
     *
     * @return
     */
    private boolean checkOrgLoad(OrgDeptUserBean bean) {
        if (clickType == OrganizationType.ORGANIZATION) {
            for (Map.Entry<String, List<OrgDeptUserBean>> entry : orgLoadMap.entrySet()) {
                if (entry.getKey().equals(bean.dept_id)) {
                    return true;
                }
            }
        } else if (clickType == OrganizationType.PART_TIME_JOB) {
            for (Map.Entry<String, List<OrgDeptUserBean>> entry : jobLoadMap.entrySet()) {
                if (entry.getKey().equals(bean.dept_id)) {
                    return true;
                }
            }
        } else if (clickType == OrganizationType.ZHISHU_ORG) {
            for (Map.Entry<String, List<OrgDeptUserBean>> entry : zhishuLoadMap.entrySet()) {
                if (entry.getKey().equals(bean.dept_id)) {
                    return true;
                }
            }
        } else if (clickType == OrganizationType.ZHISHU_UP_ORG) {
            for (Map.Entry<String, List<OrgDeptUserBean>> entry : zhishuUpLoadMap.entrySet()) {
                if (entry.getKey().equals(bean.dept_id)) {
                    return true;
                }
            }
        } else if (clickType == OrganizationType.ZHISHU_EQU_ORG) {
            for (Map.Entry<String, List<OrgDeptUserBean>> entry : zhishuEquLoadMap.entrySet()) {
                if (entry.getKey().equals(bean.dept_id)) {
                    return true;
                }
            }
        } else if (clickType == OrganizationType.GUIKOU_ORG) {
            for (Map.Entry<String, List<OrgDeptUserBean>> entry : guikouLoadMap.entrySet()) {
                if (entry.getKey().equals(bean.dept_id)) {
                    return true;
                }
            }
        } else if (clickType == OrganizationType.GUIKOU_UP_ORG) {
            for (Map.Entry<String, List<OrgDeptUserBean>> entry : guikouUpLoadMap.entrySet()) {
                if (entry.getKey().equals(bean.dept_id)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public void onEventMainThread(Map<String, Object> inParam) {
        super.onEventMainThread(inParam);
        if (inParam == null)
            return;
        if (inParam.get(EventBusConstant.TYPE) == null)
            return;
        if (EventBusConstant.FINISH_PAGE_FORWARD.equals(inParam.get(EventBusConstant.TYPE)) && recordEntity != null) {
            finish();
        }
    }

    /**
     * popupWindow的关闭方法
     */
    private void popDismiss() {
        if (popupWindow != null) {
            popupWindow.dismiss();
            popupWindow = null;
        }
    }
}
